package com.monitor.action.user;

import java.io.PrintWriter;

import com.monitor.action.MonitorActionSupport;
import com.monitor.po.Message;
import com.monitor.service.MessageService;
import com.monitor.util.Constants;
import com.monitor.util.Pager;

public class MessageAction extends MonitorActionSupport {

	private static final long serialVersionUID = 6645986454903934171L;
	private int cPage;
	private long uid;
	private Pager<Message> messages;
	private MessageService messageService;
	private long mid;
	private String midStr;

	@Override
	public String execute() throws Exception {
		cPage = cPage < 1 ? 1 : cPage;
		messages = messageService.getMessagesByUid(uid, Constants.DEFAULT_PAGESIEZE, cPage);
		return SUCCESS;
	}

	public void deleteMsg() throws Exception {
		PrintWriter out = getWriter();
		boolean success = messageService.deleteMessage(uid, mid);
		if (success) {
			out.print("success");
		} else {
			out.print("failed");
		}
		out.flush();
		out.close();
	}

	public void deleteMultiMsg() throws Exception {
		PrintWriter out = getWriter();
		boolean success = messageService.deleteMessage(uid, midStr);
		if (success) {
			out.print("success");
		} else {
			out.print("failed");
		}
		out.flush();
		out.close();
	}

	public int getcPage() {
		return cPage;
	}

	public void setcPage(int cPage) {
		this.cPage = cPage;
	}

	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}

	public Pager<Message> getMessages() {
		return messages;
	}

	public void setMessages(Pager<Message> messages) {
		this.messages = messages;
	}

	public MessageService getMessageService() {
		return messageService;
	}

	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}

	public long getMid() {
		return mid;
	}

	public void setMid(long mid) {
		this.mid = mid;
	}

	public String getMidStr() {
		return midStr;
	}

	public void setMidStr(String midStr) {
		this.midStr = midStr;
	}

}
